/*
** Copyright (C) 2009 Zhang Cong <ftofficer@ftofficer.com>
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif // HAVE_CONFIG_H

#include <liboi.h>
#include <stdio.h>

void print_logo()
{
    printf("OI Search utility with liboi version %s\n",
           PACKAGE_VERSION);
    printf("\n");
}

int main(int argc, char* argv[])
{
    oi_device_location oi_devices[16];
    int oi_device_count = 16;
    liboi_err_t err = LIBOI_OK;
    int i;

    print_logo();

	liboi_init();

    err = oi_find_all(oi_devices, &oi_device_count);
    if (err != LIBOI_OK)
    {
        fprintf(stderr, "search OI device failed: [%d] %s\n", err,
                liboi_strerror(err));
        return err;
    }

    for ( i=0; i<oi_device_count; ++i )
    {
        oi_device_location* oi_device = &oi_devices[i];
        char* oi_device_type = "unknown";

        switch (oi_device->type)
        {
            case OI_DEVICE_SSH_CONNECTED:
                oi_device_type = "ssh";
                break;
            case OI_DEVICE_USB_STORAGE:
                oi_device_type = "usb";
                break;
        }

        printf("device[%d]: %s:%s\n", i, oi_device_type, 
               oi_device->address);
    }

	liboi_cleanup();

    return 0;
}

